<?php
 
echo $this->Session->flash();
echo $this->Form->create('User');
echo $this->Form->input('name');
echo $this->Form->input('captcha');
echo $this->Html->image(array('controller' => 'Demo', 'action' => 'get_captcha'),array('id' => 'captcha_image'));
echo $this->Html->link('Reload Captcha', 'javascript:void(0);',array('id' => 'reload'));
 
echo $this->Form->end('Submit');
?>
 
<script type="text/javascript">
$(document).ready(function(){
$('#reload').click(function() {
          var captcha = $("#captcha_image");
           captcha.attr('src', captcha.attr('src')+'?'+Math.random());
          return false;
      });
});
</script>